#!/bin/bash

echo
echo
echo "!!!This script is deprecated, moving to 'tox'!!!"
echo "just run 'tox' to check code against python 2.7 and 3.4"
echo "'tox -e py2.7-test' will run just original 2.7 test, and "
echo "'tox -e pep8' will just run the pep8 check."
echo
echo

# Packages required (and Ubuntu/Debian style packages)
# Python nose tests (apt-get install python-nose)
# Python pep8 style checker (apt-get install pep8)
# Pylint error checker (apt-get install pylint)

# check exit code
function check_exit_code {
    exit_status=$1
    if [[ $exit_status != 0 ]]; then
        echo $2
        exit $exit_status
    fi
}

echo 
echo ===== Running NoseTests ==============================================
nosetests -x --with-coverage
check_exit_code $? 'PyRTL core nose tests failed. Exiting'

echo 
echo ===== Checking Core  =====================================

pylint -E pyrtl.
check_exit_code $? 'PyRTL core lint check failed. Exiting.'

pep8 --max-line-length=100 pyrtl/
check_exit_code $? 'PyRTL core pep8 check failed. Exiting.'

echo 
echo ===== Checking Examples  =====================================

pylint -E examples/*.py
check_exit_code $? 'PyRTL example link check failed. Exiting.'

pep8 --max-line-length=100 examples/*.py
check_exit_code $? 'PyRTL examples pep8 check failed. Exiting.'

echo
echo 'Tests passed.'
echo

echo ===== Building documentation =====================================
cd docs
make html
cd ..
check_exit_code $? "Docs failed to build. Exiting."

#nosetests --with-coverage --cover-erase --cover-html

exit 0
